home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
x11
/
strategy
/
xshisen-.001
/
xshisen-~
/
xshisen-1.35
/
mahjong.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-22
|
3KB
|
117 lines
#include <stdio.h>
#include "components.h"
Mahjong Mp[36];
Mahjong::Mahjong(void)
{
}
// filename1: regular piece xpm data
// filename2: selected piece xpm data
// num: ID for object instance
// closeness: Color closeness for xpm library
void
Mahjong::ReadFile(Widget w, char *filename, int num, int closeness)
{
XpmAttributes attributes;
int result;
Pixmap mask;
Colormap colormap = XDefaultColormapOfScreen(XtScreen(w));
GC gc;
XGCValues gcv;
attributes.valuemask = XpmColormap | XpmSize | XpmCloseness;
attributes.colormap = colormap;
attributes.exactColors = False;
attributes.closeness = closeness;
id = num;
result = XpmReadFileToPixmap(XtDisplay(w), XtWindow(w), filename,
&data, &mask, &attributes);
width = original_width = attributes.width;
height = original_height = attributes.height;
if (result != XpmSuccess && result != XpmColorError) {
fprintf(stderr, "XpmReadFileToPixmap failed ");
switch(result) {
case XpmOpenFailed:
fprintf(stderr, "(Cannot open xpm files)\n");
break;
case XpmFileInvalid:
fprintf(stderr, "(xpm file may be broken)\n");
break;
case XpmNoMemory:
fprintf(stderr, "(memory exhausted)\n");
break;
case XpmColorFailed:
fprintf(stderr, "(color allocation failed [closeness:%d])\n",
closeness);
break;
default:
fprintf(stderr, "(reason unknown)\n");
break;
}
fprintf(stderr, " %s\n", filename);
exit(1);
} else {
attributes.valuemask = XpmColormap;
gcv.foreground = WhitePixelOfScreen(XtScreen(w));
gc = XCreateGC(XtDisplay(w), XtWindow(w), GCForeground, &gcv);
datag = MakeHalfBrightPixmap(data, gc);
result = XpmSuccess;
XFreeGC(XtDisplay(w), gc);
}
rdata = data;
rdatag = datag;
resized = 0;
}
void
Mahjong::Resize(Widget w, GC gc, unsigned int new_width, unsigned int new_height)
{
#if DEBUG > 2
fprintf(stderr, "piece[%2.2d] resize (%d,%d)->(%d,%d)\n",
id, width, height, new_width, new_height);
#endif
if (new_width == width && new_height == height) {
return;
}
if (resized) {
XFreePixmap(XtDisplay(w), rdata);
XFreePixmap(XtDisplay(w), rdatag);
}
if (new_width == original_width && new_height == original_height) {
rdata = data;
rdatag = datag;
resized = 0;
}
else {
rdata = ResizePixmap(data, gc, new_width, new_height);
rdatag = MakeHalfBrightPixmap(rdata, gc);
resized = 1;
}
width = new_width;
height = new_height;
}
void
Mahjong::GetSize(unsigned int &w, unsigned int &h)
{
w = width;
h = height;
}
void
Mahjong::Draw(Widget w, GC gc, int x, int y, int d)
{
switch(d) {
case 1:
XCopyArea(XtDisplay(w), rdata, XtWindow(w), gc, 0, 0, width, height, x, y);
break;
case 2:
XCopyArea(XtDisplay(w), rdatag, XtWindow(w), gc, 0, 0, width, height, x, y);
break;
}
}